#！/bin/bash
function check_update_status(){
	status_=$2
	result_=`echo "$3"|sed "$p"|grep "$4"|wc -l`
	if [[ $status_ -eq 0 ]] && [[ $result_ -ge 1 ]]
	then
		echo "***"$1" execute success!"
	else
		echo "***"$1" execute false!" && exit -1
	fi
}

# 更新服务器
cmd="sudo apt-get update"
status=$?           
result=`$cmd`
match="Reading package lists..."
check_update_status "$cmd" "$status" "$result" "$match" # 获取最新资源包
cmd="sudo apt-get upgrade"
status=$?
result=`$cmd`
match="0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded."
check_update_status "$cmd" "$status" "$result" "$match" # 本机软件全部更新
cmd="sudo apt-get dist-upgrade"
status=$?
result=`$cmd`
match="0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded."
check_update_status "$cmd" "$status" "$result" "$match" # 本机系统软件更新


